package my.project.sudoku;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.content.DialogInterface;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

public class Sudoku extends Activity implements OnClickListener {

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		View continue_btn = findViewById(R.id.continue_btn);
		View newgame_btn = findViewById(R.id.new_game_btn);
		View settings_btn = findViewById(R.id.settings_btn);
		View about_btn = findViewById(R.id.about_btn);
		View exit_btn = findViewById(R.id.exit_btn);

		continue_btn.setOnClickListener(this);
		newgame_btn.setOnClickListener(this);
		settings_btn.setOnClickListener(this);
		about_btn.setOnClickListener(this);
		exit_btn.setOnClickListener(this);
	}

	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.about_btn:
			Intent i = new Intent(this, About.class);
			startActivity(i);
			break;

		case R.id.settings_btn:
			startActivity(new Intent(this, Prefs.class));
			break;

		case R.id.exit_btn:
			finish();
			break;
		case R.id.new_game_btn:
			openNewGameDialog();
			break;
		default:
			break;
		}

	}

	/**
	 * Choose a difficulty level 
	 */
	private void openNewGameDialog() {
		new AlertDialog.Builder(this).setTitle(R.string.new_game_title).setItems(
				R.array.difficulty, new DialogInterface.OnClickListener() {

					public void onClick(DialogInterface arg0, int arg1) {
						// TODO Auto-generated method stub
						startGame(arg1);
					}
				}).show();
	}

	/**
	 * Start game 
	 * @param i
	 * 		The number of ..............
	 */
	private void startGame(int i) {
		Log.d(getClassName(), "Clicked on " + i);
		Intent intent = new Intent(this, Game.class);
		//intent.putExtra(Game., i);
		startActivity(intent);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.menu, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.menu:
			Intent i = new Intent(this, Prefs.class);
			startActivity(i);
			return true;
		}

		return false;
	}

	/**
	 * Return the name of class
	 */
	public String getClassName() {
		return getClass().getName();
	}

}